<?php
/**
 * Created by PhpStorm.
 * User: fengsen
 * Date: 16-7-15
 * Time: 上午11:15
 */
require_once ('clSqlOperation.php');
require_once ('clJson.php');

class clInReg extends clJson
{
    private $userName;
    private $userPw;
    private $userPh;
    private $backVal;

    function __construct($requestJson)
    {
        parent::__construct($requestJson);
        $this->userName = parent::fnGetJson()['user_name'];
        $this->userPw = parent::fnGetJson()['user_passwd'];
        $this->userPh = parent::fnGetJson()['user_phone'];
        $this->backVal = null;
    }

    /**
     * @return bool|null
     *function:实现用户的登录功能
     *parament:
     */
    function fnCheck(){
        $sqlQuery = new clSqlOperation("user_name,user_passwd","user_info","user_name='$this->userName'",null);
        $result = $sqlQuery->fnGetOne();
        if($this->userName == $result['user_name'] && $this->userPw == $result['user_passwd']){
            $this->backVal = true;
        }
        else
            $this->backVal = false;
        return $this->backVal;
    }

    /**
     * @return bool|null
     *function:实现用户的注册功能
     *parament:
     */
    function fnRegist(){
        if (!is_numeric($this->userPh)) {
            $this->backVal = false;
        }elseif (preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $this->userPh) ? true : false){
            $userInfo = array(
                'user_name' => $this->userName,
                'user_passwd' => $this->userPw,
                'user_phone' => $this->userPh
            );
            $sqlQuery = new clSqlOperation($userInfo,"user_info",null,null);
            $result = $sqlQuery->fnInsert();
            if($result != null)
                $this->backVal = true;
            else
                $this->backVal = false;
        }else
            $this->backVal = false;
        return $this->backVal;
    }
}